package com.corgi.multi.anno.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
   * @类名：         <p>DynamicDataSourceContextHolder</p>
   * @功能描述： <p>TODO</p>
   * @作者信息： <p>dengmiao</p>
   * @创建时间： <p>2018年5月6日下午1:02:24</p>
   * @修改备注：
 */
public class DynamicDataSourceContextHolder {

	private static List<String> dataSourceIds = new ArrayList<>();
	
	//<dataSourceIds,weight>
	private static Map<String, Integer> weightMap = new HashMap<>();
	
	//map<当前线程id,String>
	private static final ThreadLocal<String> local = new ThreadLocal<>();
	
	public static void setDataSource(String dataSource){
		local.set(dataSource);
	}
	
	public static String getDataSource(){
		return local.get();
	}
	
	public static boolean containsDataSource(String dataSource){
		return dataSourceIds.contains(dataSource);
	}

	public static List<String> getDataSourceIds() {
		return dataSourceIds;
	}

	public static Map<String, Integer> getWeightMap() {
		return weightMap;
	}

	public static void setWeightMap(Map<String, Integer> weightMap) {
		DynamicDataSourceContextHolder.weightMap = weightMap;
	}

	public static void setDataSourceIds(List<String> dataSourceIds) {
		DynamicDataSourceContextHolder.dataSourceIds = dataSourceIds;
	}
}
